import { reqGoodDetailInfoData } from "../../api/index";
const state = {
  goodsDetailInfo: {},
};
const actions = {
  async getGoodDetailInfoData({ commit }, id) {
    const result = await reqGoodDetailInfoData(id);
    if (result.code === 200) {
      commit("SAVE_GOODS_DETAIL_INFO", result.data);
    } else {
      console.log(result.message);
    }
  },
};
const getters = {
    categoryView(state){
        return state.goodsDetailInfo.categoryView || {}
    },
    skuInfo(state){
        return state.goodsDetailInfo.skuInfo||{}
    },
    spuSaleAttrList(state){
        return state.goodsDetailInfo.spuSaleAttrList||{}
    }
};
const mutations = {
  SAVE_GOODS_DETAIL_INFO(state, goodsDetailInfo) {
    state.goodsDetailInfo = goodsDetailInfo;
  },
  UPDATE_IMG_DEFAULT_URL(state,imgUrl) {
    state.goodsDetailInfo.skuInfo.skuDefaultImg = imgUrl
  }
};
export default {
  namespaced: true,
  state,
  actions,
  getters,
  mutations,
};
